#!/bin/sh

uci set luci.main.mediaurlbase='/luci-static/argon'
uci commit luci

#timezone
uci set system.@system[0].timezone=CST-8
uci set system.@system[0].zonename=Asia/Shanghai
uci commit system

#ssrp
#sed -i 's/local ucic = uci.cursor()/local ucic = luci.model.uci.cursor()/g' /usr/share/shadowsocksr/subscribe.lua
#sed -i "s/'cbid.shadowsocksr.'/'widget.cbid.shadowsocksr.'/g" /usr/lib/lua/luci/view/shadowsocksr/ssrurl.htm

#HW-RNG
uci set system.@rngd[0].enabled="1"
uci set system.@rngd[0].device="/dev/hwrng"
uci commit system

#feed
sed -i 's,21.02,21.02-SNAPSHOT,g' /etc/opkg/distfeeds.conf
sed -i 's,downloads.openwrt.org,mirror.sjtu.edu.cn/openwrt,g' /etc/opkg/distfeeds.conf

#uhttpd
uci set uhttpd.main.rfc1918_filter=0
uci set uhttpd.main.redirect_https=0
uci commit uhttpd
/etc/init.d/uhttpd restart

#firewall
uci set firewall.@defaults[0].fullcone='1'
uci commit firewall

#upnp
uci set upnpd.config.igdv1='1'
uci set upnpd.config.enabled='1'
uci del upnpd.config.enable_upnp
uci del upnpd.config.enable_natpmp
uci set upnpd.config.external_iface='wan'
uci commit upnpd

#SSL
sed -i 's,#devcrypto,devcrypto,g' /etc/ssl/openssl.cnf
sed -i 's,#USE_SOFTDRIVERS = 2,USE_SOFTDRIVERS = 1,g' /etc/ssl/openssl.cnf

#neteasemusic
#echo "59.111.239.62 httpdns.n.netease.com" >> /etc/hosts && cat /etc/hosts | sort | uniq > /tmp/tmp_hosts && cat /tmp/tmp_hosts > /etc/hosts

#chinalist
echo "10 2 * * * chinadnslist &" >> /etc/crontabs/root && cat /etc/crontabs/root | sort | uniq > /tmp/tmp_cron_root && cat /tmp/tmp_cron_root > /etc/crontabs/root
echo "20 2 * * * /usr/share/MosChinaDNS/update_list.sh &" >> /etc/crontabs/root && cat /etc/crontabs/root | sort | uniq > /tmp/tmp_cron2_root && cat /tmp/tmp_cron2_root > /etc/crontabs/root

#openclash
echo "/etc/openclash/" >> /etc/sysupgrade.conf && cat /etc/sysupgrade.conf | sort | uniq > /tmp/tmp_sysupgrade_conf && cat /tmp/tmp_sysupgrade_conf > /etc/sysupgrade.conf

#dockerman
sed -i 's,/opt,/overlay,g' /etc/config/dockerman

#dnsmasq
uci set dhcp.lan.ra='hybrid'
uci set dhcp.lan.ndp='hybrid'
uci set dhcp.lan.dhcpv6='hybrid'
uci set dhcp.lan.ra_management='1'
uci del dhcp.@dnsmasq[0].rebind_protection='1'
uci commit dhcp
sed -i '/log-facility/d' /etc/dnsmasq.conf
echo "log-facility=/dev/null" >> /etc/dnsmasq.conf

#packet_steering
uci set network.globals.packet_steering='1'
uci commit network

#SSRP
uci set shadowsocksr.@global[0].gfwlist_url='https://cdn.jsdelivr.net/gh/Loyalsoldier/v2ray-rules-dat@release/gfw.txt'
uci set shadowsocksr.@global[0].chnroute_url='https://cdn.jsdelivr.net/gh/QiuSimons/Chnroute@master/dist/chnroute/chnroute.txt'
uci commit shadowsocksr

ln -sf /sbin/ip /usr/bin/ip
ln -sf /usr/bin/wget /usr/bin/wget-ssl

opkg flag hold luci-app-ddns
opkg flag hold luci-i18n-ddns-zh-cn
opkg flag hold ddns-scripts
opkg flag hold ddns-scripts_cloudflare.com-v4
opkg flag hold luci-app-firewall
opkg flag hold firewall
opkg flag hold dnsmasq-full

#sync; echo 3 > /proc/sys/vm/drop_caches

#luci cache
rm -rf /tmp/luci-modulecache
rm -f /tmp/luci-indexcache

service shortcut-fe stop
rm -rf /etc/rc.d/S90shortcut-fe

exit 0
